package com.kasa.zto.common;

import java.nio.ByteBuffer;
import java.sql.Time;
import java.util.Date;

import com.kasa.zto.NumberUtils;
import com.kasa.zto.SOSEncoder;

public class Demo
{
    public static void main(String[] args)
    {
        CommHead head = new CommHead();
        head.cmdCode = 3055;
        head.moduleName = "storagemodule";
        head.userName = "admin";
        head.messageType = CommConstant.MESSAGE_TYPE_ASYN;
        
        PczbljgjRequest request = new PczbljgjRequest();
        request.YSJH = "";
        request.CPHM = "粤B0027M";
        request.RQ = new Date();// 日期 not null
        request.SJ = new Time(System.currentTimeMillis());// 时间 not null
        request.DQZT = "行驶";// 当前状态 null
        request.JINGDU = "234.452D";// 经度 null
        request.WEIDU = "742.965D";// 纬度 null
        request.DD = "广州大道";// 地点 null
//        request.SPEED;// 速度 null
//        request.YL;// 油量 null
//        request.WD;// 温度 null
//        request.SD;// 湿度 null
        
        LancomeData data = new LancomeData();
        data.head = head;
        data.data = request;
        
        try
        {
            SOSEncoder encoder = new SOSEncoder();
            data.encode(encoder);
            byte[] content = encoder.getBytesData();
            content = Tools.gZip(content);
            
            int length = content.length;
            byte[] size = NumberUtils.int2byte(length);
            
            ByteBuffer buffer = ByteBuffer.allocate(4 + length);
            buffer.put(size);
            buffer.put(content);
                        
            //然后发送buffer里的字节数组就好
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}